<%@page import="java.util.Comparator"%>
<%@page import="java.util.Collections"%>
<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="java.util.ArrayList, db.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"/>
<!-- Icons for Web App
<link rel="apple-touch-icon" sizes="114x114" href="images/nav/index@2x.png">
<link rel="apple-touch-startup-image" href="images/splash/splash-screen.png" media="screen and (max-device-width: 320px)" />
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="images/splash/splash-screen@2x.png" />
-->
<title>Frontera Pesos Login</title>
<link href="styles/style.css" rel="stylesheet" type="text/css">
<link href="styles/type.css" rel="stylesheet" type="text/css">
<link href="styles/buttons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" media="only screen and (-webkit-min-device-pixel-ratio: 2)"	type="text/css" href="styles/highdpi.css" />

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="scripts/highdpi.js"></script>
<script type="text/javascript" src="scripts/custom.js"></script>
<!-- utility js -->
<script type="text/javascript" src="../scripts/fronteraWebUtility.js"></script> 
 <script>
 
 
 function editPro(task,statusType,itemID)
	{
	 //alert(task + " " + itemID)
	 if(task == "update")
		{
		var UrlLink = "editProfile.jsp?itemID="+itemID;
		window.location.href=UrlLink;
		}
	 else if (task ==  "Delete")
		 {
		 
		 var answer = confirm("Are you sure you would like to de-activate this customer?");
			
		if(answer)
				{
					document.getElementById("custID").value = itemID;
					document.getElementById("statusType").value = statusType;
			    	document.getElementById("pesoEditCustomer").submit();
			    	
						
				}
			else
				{
				 return;
				}
		 
		 }
	 else if (task == "activate")
		 {
		 var answer = confirm("Are you sure you would like to Activate this customer?");
			
			if(answer)
					{
						document.getElementById("custID").value = itemID;
						document.getElementById("statusType").value = statusType;
						document.getElementById("pesoEditCustomer").submit();
					}
				else
					{
					 return;
					}	 
		 }
	}
function formSubmitRule()
{
document.getElementById("addrule").submit();
}
function formSubmitCampaign()
{
document.getElementById("addcampaign").submit();
}
function formSubmitCustomer()
{
document.getElementById("editcustomer").submit();
}
function formSubmitBirthday()
{
document.getElementById("birthday").submit();
}
</script>
</head>

<body>
<% DBHelper helper = new DBHelper();
    String serverName =  request.getRemoteHost();
	String _errorMessage = "";
	String _userName = "";
	String _loginID = "";
	String displayRewardsSec = "none";
	int storeCkInId = 0;
	int admin = 0;
	int server = 0;
	int checkID = 0;
	String showAdminBtn = "none";
	String showServerBtn = "none";
	
	Cookie[] cookies = request.getCookies();
	ArrayList<UserData> userInfo =  new ArrayList<UserData>();
	ArrayList<Coupons> couponInfo =  new ArrayList<Coupons>();
	ArrayList<Campaign> campaignInfo =  new ArrayList<Campaign>();
	ArrayList<StoreLocation> storeInfo =  new ArrayList<StoreLocation>();
	 ArrayList<UserData> customerInfo =  new ArrayList<UserData>();
	int id = -1;
	 Enumeration<String> enumeration = request.getParameterNames();
	 while (enumeration.hasMoreElements()) {
	     String parameterName = (String) enumeration.nextElement();
	     	     
	     System.out.println("Parameter = " + parameterName + " val = " + request.getParameter(parameterName));
	     
	 }
	
	 
	if(session.getAttribute("customerInfo") != null)
		 {
		 	Object t = session.getAttribute("customerInfo");
		 	customerInfo = (ArrayList<UserData>) t;
		 	
		 	if(request.getParameter("iSort") != null && request.getParameter("iSort").equals("pesos"))
		 	{
		 		Collections.sort(customerInfo, new Comparator<UserData>(){
			 		  public int compare(UserData s1, UserData s2) {
			 		    return s1.getTotalPesos() - (s2.getTotalPesos());
			 		  }
			 		});
		 	}
		 	if(request.getParameter("iSort") != null && request.getParameter("iSort").equals("last"))
		 	{
		 		Collections.sort(customerInfo, new Comparator<UserData>(){
			 		  public int compare(UserData s1, UserData s2) {
			 		    return s1.getUserFullName().compareToIgnoreCase(s2.getUserFullName());
			 		  }
			 		});
		 	}
		 	
		 	
		 }	
	
	
	
	if(session.getAttribute("adminRights") != null)
	{
		   
		    Object g =  session.getAttribute("adminRights");
		    admin = Integer.parseInt(g.toString());
		    if(admin == 1)
			{
		    	 showAdminBtn = "inline";
			}
		   
		   
		    System.out.println(" showAdminBtn ==  " + admin);
	}
	if(session.getAttribute("serverRights") != null)
	{
		   
		    Object g =  session.getAttribute("serverRights");
		    server = Integer.parseInt(g.toString());
		    if(server == 1)
			{
		    	showServerBtn = "inline";
			}
		    
		    System.out.println(" showServerBtn ==  " + server);
	}


 	%>
<div class="landing-page">
	<p class="center-text landing-logo shadow">
    	<img class="replace-2x" width="200" src="../assets/frontera-pesos-logo.png" alt="img">
	      
    </p>
    
    <center>
     
	<div class="tablet-box-expanded" style="width:780px;">
 
      <div class="tablet-customer" style="width:780px;">
        
        <p>
        <span style="display:<%=showAdminBtn%>">
        <a href="admin-view.jsp">Administration</a> - <a href="admin-view-customer.jsp">Customer Info</a> - 
        <a  href="server.jsp" style="display:<%=showServerBtn%>" >Server</a> -
       
        </span>
        <span>
         <a href="admin-view-faq.html">Faq</a> - <a href="userHomePage.jsp">Home</a></span>
         </p>
        <span>
        <p><a href="javascript:void(0);" onClick="logUserOut();"><strong>Logout</strong></a><strong></strong></p>
        </span>
        <p>&nbsp;</p>
        <h2>Customer List</h2>
        <p>&nbsp;</p>
        <p>Sort by: <a href="admin-view-customer.jsp?iSort=last">Customer Last Name</a>, <a href="admin-view-customer.jsp?iSort=pesos">Total Pesos</a></p>
        <p>&nbsp;</p>
        <style type="text/css">
		table{
			border:solid #666 medium;
			margin-left:auto;
			margin-right:auto;
		}
		
			tr:nth-child(even) { background: #FFF; }
		tr:nth-child(odd) { background: #EEE; }
		
		.toprow{
		background-color:#red;
		font-size:1.5em;
		}
		
		.td{
			border:1px solid #000;
		}
		
		
		
	

</style>
	
       <form name="pesoEditCustomer" id="pesoEditCustomer" action="../Admin" method="post">
        <input type="hidden" name="custID" id="custID" />
        <input type="hidden" name="adminRequestType" id="adminRequestType" value="deleteActCust"  placeholder="adminRequestType" />
       <input type="hidden" name="statusType" id="statusType"  />
       
        <table width="745">
          <tr class="toprow">
            <td><h5>Customer Name</h5></td>
            <td><h5>Total Pesos</h5></td>
            <td><h5>Email</h5></td>
            <td><h5>Telephone</h5></td>
            <td><h5>Birthday</h5></td>
            <td><h5>Active</h5></td>
            <td><h5>Remove</h5></td>
            <td><h5>Edit</h5></td>
          </tr>
           <% for(int i = 0; i < customerInfo.size(); i++) { 
    
    		
          		UserData customerList = customerInfo.get(i);
          		
          		%>
          <tr>
            <td><%=customerList.getUserFullName() %></td>
            <td><%=customerList.getTotalPesos() %></td>
            <td><%=customerList.getUserEmail() %></td>
            <td><%=FormatAndValidation.formatPhoneNumber(customerList.getPhoneNumber()) %></td>
            <td>
            <%if(customerList.getUserBirthday()== null)
            	{%>
            	&nbsp;
            	<%}
            	else 
            	{%>
            	<%=customerList.getUserBirthday() %>&nbsp;
			   	
            	<%} %>
            
            
            </td>
            <td>
            	<%if(customerList.getUserActive()== 1)
            	{%>
            	<img src="../assets/tick.png" alt="img"  class="replace-2x">&nbsp;
            	<%}
            	else 
            	{%>
            	<input name="#active" type="checkbox" id="#active" onchange="editPro('activate',1,<%=customerList.getUserID() %>)">&nbsp;
			   	
            	<%} %>
            </td>
            <td>
            	<a href="javascript:void(0)" onClick="editPro('Delete',0,<%=customerList.getUserID() %>)" title="Delete" >
			   		<img src="../assets/cross.png" alt="img"  class="replace-2x">
				</a>
            </td>
            <td>
            <a href="javascript:void(0)" onClick="editPro('update','update',<%=customerList.getUserID() %>)" title="Update" >
			   <img src="../assets/update.jpg" alt="img" width="70"  class="replace-2x">
			</a>
		
            </td>
          </tr>
          <%} %>
          
        </table>
        
        </form>
      </div>
	</div>
	
    </center>
    

<!--	<p class="login-note shadow"><strong>*</strong>Forgot my Password</p> -->
<div style="height:25px;"></div>
</div>
<style>
#registration-block{
	display:none;
}
</style>

    </div>
<script>
    $('#register-button').click(function() {
      $('#registration-block').fadeIn('slow', function() {
        // Animation complete
      });
    });
</script>

</body>
</html>
